/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon
 												
Class							:				AbsoluteNumberOfUnitsOfTypeSoftCondition
 
Function						: 				Provides a class for holding 
												the condition for number of certain 
												units
****************************************************************************/
package planninglanguage.softconditions;

import base.WargusGameState;
import base.WargusPlayer;
import base.WargusStateImporter;
import base.WargusUnit;


public class RelativeNumberOfUnitsOfTypeSoftCondition extends SoftCondition {

	String m_unitType;
	int m_minimumNumber;
	int m_initialNumber;
	int m_playerID;
	
	public RelativeNumberOfUnitsOfTypeSoftCondition(String a_unitType,int a_playerID,int a_minimumNumber,int a_initialNumber)
	{
		m_unitType = a_unitType;
		m_playerID = a_playerID;
		m_minimumNumber = a_minimumNumber;
		m_initialNumber = a_initialNumber;
	}
	public String toString(int tabs)
	{
		String n = super.toString(tabs);
		n = n+ "Player Id is:" + m_playerID + "\n"; 
		n = n + "Unit Type is" + m_unitType + "\n";
		n = n + "Minimum Number is" + m_minimumNumber + "\n";
		n = n + "Initial Number is" + m_initialNumber + "\n";
		return n; 
	
	}
	
	public float test(WargusGameState a_gameState)
	{
		WargusPlayer p = a_gameState.getPlayer(m_playerID);
		
		if (p!=null) {
			int num=0;
			for(WargusUnit u:p.getUnits()) {
				if (WargusStateImporter.unitTypeToString(u.getType()).equals(m_unitType)) num++;			
			}
			
			if (num - m_initialNumber>=m_minimumNumber) {
				return 1.0f;
			} else {
				int progress = num - m_initialNumber;
				if (progress<0) progress = 0;
				return ((float)(progress))/((float)(m_minimumNumber));
			}
		}	
		return 0.0f;
	}
	
}
